<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" href="http://apps.bdimg.com/libs/bootstrap/3.3.0/css/bootstrap.min.css">
    <script src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/rawal/css/layui.css"  media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>

<div class="layui-form">
    <table class="layui-table">
        <colgroup>
            <col width="150">
            <col width="150">
            <col width="200">
            <col>
        </colgroup>
        <thead>
        <tr>
            <th>ID</th>
            <th>论坛类型</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody id="tbody">

        </tbody>
    </table>

    <div id="demo0"></div>
    <div id="page"></div>
</div>
<script src="/rawal/js/layui.js.下载" charset="utf-8"></script>
<script>

    $(function(){

        ajaxpage(1);
    })
    function ajaxpage(p){
        $.ajax({
            type:'post',
            url:"/admin/type/do_typelist",
            data:{page:p},
            dataType:'json',
            success:function(e){
                console.log(e);
                str="";
                $.each(e.data.data,function(i,v){
                    str+="<tr>";
                    str+="<td>"+v.id+"</td>";
                    str+="<td>"+v.cardtype+"</td>";
                    str+="<td><button ids="+v.id+"  id='del'  type='button' class='layui-btn' width='10px'>删除</button> <a href='/admin/type/typeupd?id="+v.id+"'  class='layui-btn'  >修改</a></td>";
                    str+="</tr>";
                })
                $('#tbody').html(str);
                page= parseInt(e.data.current_page);
                //返回1234
//                page=str_substr(page,1);
//                console.log(page);
                last_page=e.data.last_page;
//                alert(last_page);
                pages="";
                pages+="<button class='btn btn-default' onclick='ajaxpage(1)'>首页</button>";
                pages+="<button class='btn btn-default' onclick='page-1>1?ajaxpage(page-1):ajaxpage(1)'>上一页</button>";
                for(i=1;i<=last_page;i++){
                    console.log(i);
                    pages+="<button onclick='ajaxpage("+i+")' class='btn btn-default'>"+i+"</button>";
                }
                pages+="<button class='btn btn-default' onclick='page+1<last_page?ajaxpage(page+1):ajaxpage(last_page)'>下一页</button>";
                pages+="<button class='btn btn-default' onclick='ajaxpage(last_page)'>尾页</button>";
                $('#page').html(pages);
                //样式
            }

        })
    }
    //ajax删除
    $(document).on('click','#del',function(){
        ids=$(this).attr('ids');
        status=$(this).attr('status');
        $.ajax({
            type:'get',
            url:"/admin/type/typedel",
            data:{ids:ids,status:status},
            dataType:'json',
            success:function(e){
                if(e.code==200){
                    alert('删除成功');
                    ajaxpage(1);
                } else{
                    alert('删除失败');
                }
            }
        })
    })

</script>